package main

import (
	"io"
	"os"
)
//defer一般放在错误检查语句之后
//defer会推迟资源的释放,defer尽量不要放到循环语句里
func copyFile(dst, src string) (w int64, err error) {
	srcF, err := os.Open(src)
	if err != nil {
		return
	}
	defer srcF.Close()
	dstF, err := os.Create(dst)
	if err != nil {
		return
	}

	defer dstF.Close()

	w, err = io.Copy(dstF, srcF)

	return
}